// 网络请求记录类型
export const HttpRequestSchema = {
  id: 'string',
  url: 'string',
  method: 'string',
  headers: 'object',
  params: 'object',
  cookies: 'object',
  body: 'string',
  timestamp: 'number',
  clientHttpVersion: 'string',  // 客户端HTTP版本
  remoteHttpVersion: 'string?', // 远程服务器HTTP版本
  tlsVersion: 'string?',
  clientIp: 'string',
  remoteIp: 'string'
};

// 网络响应记录类型
export const HttpResponseSchema = {
  id: 'string',
  requestId: 'string',
  statusCode: 'number',
  headers: 'object',
  cookies: 'object',
  body: 'string',
  bodySize: 'number',
  timestamp: 'number',
  remoteHttpVersion: 'string', // 远程服务器HTTP版本
  tlsVersion: 'string?'
};

// 完整的HTTP交互记录
export const HttpTransactionSchema = {
  id: 'string',
  request: 'HttpRequest',
  response: 'HttpResponse?',
  duration: 'number?',
  createdAt: 'number'
};

// 规则配置类型
export const RuleSchema = {
  id: 'string',
  name: 'string',
  description: 'string?',
  enabled: 'boolean',
  conditions: 'array',
  actions: 'array',
  createdAt: 'number',
  updatedAt: 'number'
};

// 代理配置类型
export const ProxyConfigSchema = {
  enabled: 'boolean',
  port: 'number',
  httpsPort: 'number',
  interceptHttps: 'boolean'
};

// WebSocket消息类型
export const WebSocketMessageSchema = {
  type: 'string',
  data: 'any',
  timestamp: 'number'
};

// 工具函数：创建HTTP请求对象
export function createHttpRequest(data) {
  return {
    id: data.id || generateId(),
    url: data.url || '',
    method: data.method || 'GET',
    headers: data.headers || {},
    params: data.params || {},
    cookies: data.cookies || {},
    body: data.body || '',
    timestamp: data.timestamp || Date.now(),
    clientHttpVersion: data.clientHttpVersion || 'HTTP/1.1',
    remoteHttpVersion: data.remoteHttpVersion || undefined,
    tlsVersion: data.tlsVersion || undefined,
    clientIp: data.clientIp || '127.0.0.1',
    remoteIp: data.remoteIp || ''
  };
}

// 工具函数：创建HTTP响应对象
export function createHttpResponse(data) {
  return {
    id: data.id || generateId(),
    requestId: data.requestId || '',
    statusCode: data.statusCode || 200,
    headers: data.headers || {},
    cookies: data.cookies || {},
    body: data.body || '',
    bodySize: data.bodySize || 0,
    timestamp: data.timestamp || Date.now(),
    remoteHttpVersion: data.remoteHttpVersion || 'HTTP/1.1',
    tlsVersion: data.tlsVersion || undefined
  };
}

// 工具函数：创建HTTP事务对象
export function createHttpTransaction(data) {
  return {
    id: data.id || generateId(),
    request: data.request,
    response: data.response || null,
    duration: data.duration || null,
    createdAt: data.createdAt || Date.now()
  };
}

// 工具函数：生成唯一ID
export function generateId() {
  return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
} 